package servlet;

import service.UserService;
import service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "LogoutServlet",urlPatterns = "/LogoutServlet")
public class LogoutServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        Integer id = Integer.valueOf(request.getParameter("id"));
        //System.out.println(id);
        UserService userService = new UserServiceImpl();
        int res = 0;
        res = userService.wogout(id);

        PrintWriter out = response.getWriter();

        if (res > 0){
            out.print("{\"result\":\"成功\"}");
        }else{
            out.print("{\"result\":\"失败\"}");
        }
        out.flush();
        out.close();
    }
}
